#!/bin/bash

PING_TARGET="8.8.8.8"
MAX_TRIES=3
TRIES=0

# 检查网络连接
while true; do
    ping -c 1 $PING_TARGET > /dev/null 2>&1
    if [ $? -ne 0 ]; then
        let TRIES=TRIES+1
        echo "Network connection lost. Attempt $TRIES"
        if [ $TRIES -ge $MAX_TRIES ]; then
            # 尝试重新连接网络
            ifdown eth0 && ifup eth0
            TRIES=0
        fi
    else
        let TRIES=0
    fi
    sleep 5
done